class_name CharacterSkin
extends Node3D

@export var main_animation_player: AnimationPlayer

@onready var moving: bool = false : set = set_moving

@onready var moving_speed: float = 0.0 : set = set_moving_speed
@onready var animation_tree: AnimationTree = $AnimationTree
@onready var state_machine: AnimationNodeStateMachinePlayback = animation_tree.get("parameters/StateMachine/playback")

func _ready() -> void:
	animation_tree.active = true
	main_animation_player["playback_default_blend_time"] = 0.1

func set_moving(value: bool) -> void:
	moving = value
	if moving:
		state_machine.travel("Run")
	else:
		state_machine.travel("Idle")

func set_moving_speed(value: float) -> void:
	moving_speed = clamp(value, 0.0, 1.0)
	animation_tree.set("parameters/StateMachine/Run/blend_position", moving_speed)

func jump() -> void:
	state_machine.travel("Jump")

func land() -> void:
	state_machine.travel("Land")

func fall() -> void:
	state_machine.travel("Fall")

func attack() -> void:
	print("attack")
	animation_tree["parameters/AttackOneShot/request"] = AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE
